import axios from "axios";
import router from "@/router/index.js";
import {ElMessage} from "element-plus";
import {useUserStore} from "@/stores/useUSerStore.js";
const baseURL ="http://localhost:80"

const instance =axios.create({
    baseURL,
    timeout:10000,
    headers:{
        Authorization:useUserStore().token
    }
})

instance.interceptors.request.use(
    (config)=>{
        return config
    },
    (err) =>
    {
        return Promise.reject(err)
    }
)

instance.interceptors.response.use(
    (res) =>{
        return res.data
    },
    /* (err)=>{
        if (err.response?.status ===401)
        {
            router.push('/')
            ElMessage.error("登录身份失效，请重新登录")
        }
        return Promise.reject(err)
    } */
)

export default instance
export {baseURL}